package com.eddie.interator;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Eddie
 * @date 2022/08/03 22:21
 **/
public class InfoCollege implements College {

    private List<Department> departments;
    //保存当前  对象数组的对象个数
    int numOfDepartments = 0;

    public InfoCollege() {
        departments = new ArrayList<>();
        addDepartment("信息安全专业", "信息安全专业");
        addDepartment("网络安全", "网络安全");
        addDepartment("服务器安全", "服务器安全");
    }

    @Override
    public String getName() {
        return "计算机学院";
    }

    @Override
    public void addDepartment(String name, String desc) {
        if (numOfDepartments >= 5) {
            throw new RuntimeException("系已满");
        }
        Department department = new Department(name, desc);
        departments.add(department);
    }

    @Override
    public Iterator<Object> createIterator() {
        return new InfoCollegeIterator(departments);
    }
}
